﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace workshop3
{
    public partial class Formviewams : Form
    {
        public DataTable dtviewams = new DataTable();
        public string[] itemid = new string[20];
        bool editmode = false;
        string id;
        int num = 0;

        public Formviewams(DataTable dt)
        {
            InitializeComponent();
            dtviewams = dt;
        }

        public Formviewams(DataTable dt,bool editmode,string id)
        {
            InitializeComponent();
            dtviewams = dt;
            this.id = id;
            if (editmode ==true)
            {
                this.editmode = editmode;
                dgvviewams.ReadOnly = false;//this table just to show the data, not allow to change
                //dgvviewams.Enabled = true;
            }
        }

        private void Formviewams_Load(object sender, EventArgs e)
        {
            dgvviewams.DataSource = dtviewams;
        }

        private void dgvviewams_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (editmode)
            {
                if (e.Button == MouseButtons.Right)//right click do the delete
                {

                    itemid[num] = dgvviewams.Rows[e.RowIndex].Cells[0].Value.ToString();
                    dtviewams.Rows.Remove(dtviewams.Rows[e.RowIndex]);
                    num++;
                }
            }
        }

        private void dgvviewams_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dgvviewams_CellClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void btnadd_Click(object sender, EventArgs e)
        {
            //ClassCreateXML.deletexml("course.xml", "//AMS", id);

        }
    }
}
